<?php
!defined('IN_ROOT') && exit( 'Access Denied' );
class LoginController extends AdminModuleController 
{
	public function init() {
		
	}
	
	public function actionIndex() {
		$userName = getgpc('username', 'P');
		$passwd = getgpc('password', 'P');
		
		if(isset($_POST['username'])) {
			
			if(!$userName || !$passwd) {
				$this->alert('用户名和密码不能为空。', GODHOUSE_DOMAIN_WWW.'admin/login.htm');
			}
			error_reporting(E_ALL);
			if(!$this->UserModel->bopurui($userName, $passwd)) {
				$user = $this->UserModel->find("userName='{$userName}' AND passwd='".md5($passwd)."'");
				if($user && $this->getState('authentication')) {
					$this->setState('adminId', $user['userId']);
					$this->setState('adminName', $user['userName']);
					$this->setState('adminGroupId', $user['groupId']);
					$this->redirect('/admin/index.htm');
				} else {
					$this->alert('用户名和密码错误。', GODHOUSE_DOMAIN_WWW.'admin/login.htm');
				}
			}
		}
		$this->setState('adminItems', NULL);
		$this->display('admin_login');
	}
	
	public function actionLogout() {
		$this->setState('adminId', NULL);
		$this->setState('adminName', NULL);
		$this->setState('adminGroupId', NULL);
		$this->setState('adminItems', NULL);
		$this->redirect('/admin/login.htm');
	}
}